package io;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author IT枫斗者
 * @ClassName FileOutputStreamQ02.java
 * @From www.javatiaozao.com
 * @Description TODO
 */
public class FileOutputStreamQ02 {
    public static void main(String[] args) {
        //用异常捕获
        //需求：用finally来实现关闭资源
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("myStream\\333.txt");
            fos.write("hello,美女你好！".getBytes());
        } catch (IOException o) {
            o.printStackTrace();
        } finally {
            //关闭资源
            if(fos != null) {
                try {
                    fos.close(); //fos不能为空
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
